#ifndef COLLECTION_H
#define COLLECTION_H

#include "video.h"
#include <QtSql>
#include <QMutex>


/**
  This abstracts away the access to whatever stores information
  about the collection. Currently it just uses SQLite.
  */

class Collection
{
public:

    /// Lists all tags matching `filter`
    static QStringList listTags(QString filter = QString());

    /// Gets the videos that matches all the given tags
    static QList<Video> getVideos(QStringList tags);

    /// Gets the cover for a give video
    static QUrl getCover(QString video);

    /// Gets the files for a given video
    static QList<QUrl> getFiles(QString video);

    /// Gets the tags for a given video
    static QStringList getTags(QString video);

    /// Gets the thumbnail for a given file
    static QUrl getThumbnail(QString url);

    /// Gets the path to a video folder
    static QString getPath(QString video);


    /// Checks to see if a file is already in the DB, used by the scanner
    static bool fileIsRegistered(QString url);


    /// Adds the named tag to `video`
    static bool addTag(QString name, QString video);

    /// Adds a new video
    static void addVideo(QString name, QString cover, QString path, QStringList tags, QStringList files, QStringList thumbnails);

    /// Adds a given file to `video`
    static void addFile(QString file, QString video);

    /// Sets the thumbnail for a file
    static void setThumbnail(QString file, QString thumbnail);


    /// Closes the database connection
    static void close() { m_db.close(); }

public:
    /// Ensures that we are connected to the database, or otherwise connects it
    static bool ensureConnection();

    static QSqlDatabase m_db;
    static QMutex m_mutex;
};

#endif // COLLECTION_H
